//
//  LZTextFiledExtension.swift
//  halikaPeso
//
//  Created by L-zh on 2024/12/16.
//
import UIKit

extension UITextField {
    public func textFieldSelectedTextDidBeginEditing(_ textField: UITextField) {
        let endDocument = textField.endOfDocument
        guard let end = textField.position(from: endDocument, offset: 0) else { return }
        guard let start = textField.position(from: end, offset: -((textField.text ?? "") as NSString).length) else { return }
        textField.selectedTextRange = textField.textRange(from: start, to: end)
    }

    public func textFieldSelectedTextShouldEndEditing(_ textField: UITextField) -> Bool {
        let beginDocument = textField.beginningOfDocument
        guard let end = textField.position(from: beginDocument, offset: 0) else { return true }
        guard let start = textField.position(from: beginDocument, offset: 0) else { return true }
        textField.selectedTextRange = textField.textRange(from: start, to: end)
        return true
    }
}

